<?php

class Service_NovelModel {

    private $_novelDao;
    private $_novelcategoryDao;
    private $_novelchapterDao;
    private $_novelbookcaseDao;
    private $_novelChannelRelation;
    private $_novelChannelCategory;
    //小说首页banner
    private $_novelBanner;
    private $_userDao;
    private $_userConsume;

    public function __construct ()
    {
        $this->_novelDao                = new Dao_NovelModel();
        $this->_novelcategoryDao        = new Dao_NovelCategoryModel();
        $this->_novelchapterDao         = new Dao_NovelChapterModel();
        $this->_novelbookcaseDao        = new Dao_NovelBookcaseModel();
        $this->_novelChannelRelation    = new Dao_NovelChannelRelationModel();
        $this->_novelChannelCategory    = new Dao_NovelChannelCategoryModel();
        $this->_novelBanner             = new Dao_BannerModel();
        $this->_userDao                 = new Dao_UserModel();
        $this->_userConsume             = new Dao_UserConsumeModel();
    }
    
    public function getNovelInfo( $param = [], $uid = false , $record = [] )
    {
        if(!isset($param['novel_id'])){
            return false;
        }
        $where = array ();
        $where['novel_id'] = $param['novel_id'];
        $info = $this->_novelDao->getNovelInfo($where);
        if( empty( $info ) ){
            return false;
        }
        
        $case_type = 1;
        if( $uid ){
            $case_type = $this->_novelbookcaseDao->checkInBookCase( $info['novel_id'] , $uid );
        }
        $info['bookcase'] = $case_type;
        $info['category'] = '';
        if( isset( $info['novel_category'] ) && $info['novel_category'] != 0 ){
            $category = $this->_novelcategoryDao->getByCategoryId( array ( 'category_id' => $info['novel_category'] ) );
            $info['category'] = isset( $category['cate_name'] ) ? $category['cate_name'] : '暂无分类';
        }
        if( $record ){
            $r = array_column( $record , null , 'novelid' );
            if( isset( $r[ $info['novel_id'] ] ) ){
                $info['read_record'] = [
                    'type' => 1,
                    'id'   => $r[ $info['novel_id'] ][ 'chapterid' ],
                    'info' => $this->_novelchapterDao->getChapterInfo( array( 'chapterid' => array( 'chapter_id' , $r[ $info['novel_id'] ][ 'chapterid' ] ) ) ),
                ];
            }else{
                $chapters = $this->_novelchapterDao->getNovelChapterList( array ( 'chapter_novel_id' => $info['novel_id'] ) );
                $info['read_record'] = [
                    'type' => 2,
                    'id'   => $chapters[0][ 'chapter_id' ],
                ];
            }
        }else{
            $chapters = $this->_novelchapterDao->getNovelChapterList( array ( 'chapter_novel_id' => $info['novel_id'] ) );
            $info['read_record'] = [
                'type' => 2,
                'id'   => $chapters[0][ 'chapter_id' ],
            ];
        }
        return $info ? $info : false;
    }
    
    /**
     * 获取小说列表
     * @return type
     */
    public function getList( $param = [] )
    {
        $where = [];
        if( $param['novelids'] ){
            $where['novelids'] = array ( 'novel_id' , $param['novelids'] );
        }
        $list = $this->_novelDao->getNovelList( $where );
        return $list ? $list : false;
    }
    
    /**
     * 获取小说分类列表
     */
    public function getCategoryList()
    {
        $list = $this->_novelcategoryDao->getNovelCategoryList();
        return $list ? $list : false;
    }
    
    /**
     * 获取分类信息
     */
    public function getCategoryInfo( $id )
    {
        if(intval($id) <= 0){
            return [];
        }
        $info = $this->_novelcategoryDao->getByCategoryId( array( 'category_id' => $id ) );
        return $info ? $info : [];
    }
    
    /**
     * 获取小说章节列表
     */
    public function getChapterList( $param = [] )
    {
        $where = array ();
        $where['page']             = $param['page'];
        $where['chapter_novel_id'] = isset( $param['chapter_novel_id'] ) ? $param['chapter_novel_id'] : 0;
        $where['chapter_id'] = isset( $param['chapter_id'] ) ? $param['chapter_id'] : 0;
        $list = $this->_novelchapterDao->getNovelChapterList($where);
        return $list ? $list : [];
    }
    
    /**
     * 获取小说章节内容
     */
    public function getChapterContent( $param = [] )
    {
        $res = [
            'content' => '',
            'need_pay' => 0,
        ];
        if( !$param['chapter_novel_id'] && !$param['chapter_id'] ){
            return false;
        }
        $info = $this->_novelDao->getNovelInfo( [ 'novel_id' => $param['chapter_novel_id'] ] );
        if( !info ){
            $res = [
                'content' => '<p>小说不存在</p>',
                'need_pay' => 0,
            ];
            return $res;
        }
        
        $redis = RedisTool::getInstance();
        $chapters = json_decode($redis->get( "NOVEL:CHAPTER:NOVEL_CHAPTER_KEY_".$param['chapter_id'] ),true);
        if( !$chapters ){
            $where['chapter_novel_id'] = $param['chapter_novel_id'];
            $where['chapter_id'] = $param['chapter_id'];
            $chapters = $this->_novelchapterDao->getNovelChapterList($where);
        }
        $c_k_v = array_column( $chapters , null , 'chapter_id' );
        unset($chapters);
        $novel_charge_dao = new Dao_NovelChargeModel();
        $charge = $novel_charge_dao->getByNovelId( [ 'novel_id' => $param['chapter_novel_id'] ] );
        if( $charge ){
            if( $c_k_v[$param['chapter_id']]['chapter_ispay'] == 1 ){
                $res['need_pay'] = $charge['charge_price'];
            }
        }
        $content = $redis->get( "NOVEL:CONTENT:{$param['chapter_novel_id']}:{$param['chapter_id']}" );
        if( !$content ){
            $patch = APPLICATION_PATH."/txt/{$info['novel_pinyin']}/{$info['novel_title']}/{$param['chapter_novel_id']}_{$param['chapter_id']}.txt";
            if( file_exists($patch) ){
                $content = file_get_contents($patch);
                $enCode = 'utf-8';
                $strEncode = mb_detect_encoding($content, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
                if( $strEncode != $enCode )
                {
                    $content = mb_convert_encoding( $content , $enCode , $strEncode );
                }
                $redis->set( "NOVEL:CONTENT:{$param['chapter_novel_id']}:{$param['chapter_id']}" , $content , 86400 );
            }else{
                $content = "<p>获取内容失败</p>";
            }
        }
        if($res['need_pay'] > 0){
            $content = $this->subContent($content);
        }
        $res['content'] = $content;
        return $res;
    }
    
    private function subContent( $content )
    {
        $arr_temp = explode("</p>",$content);
        $arr = array_slice( $arr_temp , 0 , 6 );
        unset($content);
        $str = implode("</p>",$arr);
        unset($arr);
        return $str;
    }
    
    /**
     * 把字符串转成html代码
     * @param 参数1，需要进行替换的字符串
     * 返回值，字符串
     */
    private function ToHtml($str)
    {
            //键为需要替换的字符，值为替换后的字符
            //注：此函数在同条件下，比str_replace循环替换百万次快一半
            $array = array(
                    "\r\n"	=>	'<br/>',
                    "\r"	=>	'<br/>',
                    "\n"	=>	'<br/>',
                    "\t"	=>	'　　',
                    '&#39;'		=>	"'",
                    '{#lt}'		=>	"<",
                    '{#gt}'		=>	'>',
            );

            return strtr($str,$array);
    }
    
    /**
     * 添加到书架
     */
    public function addBookCase( $novelid = 0 , $uid = 0 )
    {
        if( !$novelid || !$uid ){
            return false;
        }
        $case_type = $this->_novelbookcaseDao->checkInBookCase( $novelid , $uid );
        if( $case_type == 2 ){
            return array('msg' => '已在书架');
        }
        $time = date('Y-m-d H:i:s');
        $new_data                           = array ();
        $new_data['case_user_id']           = $uid;
        $new_data['case_novel_id']          = $novelid;
        $new_data['case_create_time']       = $time;
        $res = $this->_novelbookcaseDao->addBook($new_data);
        return $res;
    }
    
    /**
     * 从书架中删除
     */
    public function delBookCase( $novelid = 0 , $uid = 0 )
    {
        if( !$novelid || !$uid ){
            return false;
        }
        $where            = array ();
        $where[]          = array ( 'case_user_id' , $uid );
        $where[]          = array ( 'case_novel_id' , $novelid );
        $res = $this->_novelbookcaseDao->delBook($where);
        return $res;
    }
    
    /**
     * 判断是否在书架
     */
    public function checkInCase( $novelid , $uid = false )
    {
        if( !$uid ){
            return 1;
        }
        $res = $this->_novelbookcaseDao->checkInBookCase( $novelid , $uid );
        return $res;
    }
    
    /**
     * 获取用户书架
     */
    public function getUserBookCase( $uid = 0 , $records = [])
    {
        $res = [
            'list'  => [],
            'count' => 0,
        ];
        if( !$uid ){
            return [];
        }
        $res1 = $this->_novelbookcaseDao->getUserBookCase( $uid );
        $novelids = array_column ( $res1 , 'case_novel_id' );
        if($novelids){
            $where   = array ();
            $where['novelids'] = array ( 'novel_id' , $novelids );
        }
        $novels   = $this->_novelDao->getNovelList( $where );
        if( $novels ){
            $redis = RedisTool::getInstance();
            if( $records ){
                $records_k_v = array_column ( $records , null , 'novelid' );
                $chapters = $this->_novelchapterDao->getChapterList( array ( 'chapterids' => array ( 'chapter_id' , array_column ( $records , 'chapterid' ) ) ) );
                unset( $records );
                
                $chapters_k_v = [];
                if( $chapters ){
                    $chapters_k_v = array_column ( $chapters , null , 'chapter_id' );
                }
                
                $common_tools = new Tools_Common();
                foreach($novels as $k=>$v){
                    $c = $this->_novelchapterDao->getNovelChapterList( array( 'chapter_novel_id' => $v['novel_id'] ) );
                    $novels[ $k ][ 'chapter_id' ] = isset( $records_k_v[ $v[ 'novel_id' ] ]) ? $records_k_v[ $v[ 'novel_id' ]][ 'chapterid' ] : $c[0]['chapter_id'];
                    $novels[ $k ][ 'time' ] = isset( $records_k_v[ $v[ 'novel_id' ] ]) ? $common_tools->time_format($records_k_v[ $v[ 'novel_id' ]][ 'time' ]) : '';
                    $novels[ $k ][ 'chapter_name' ] = isset( $records_k_v[ $v[ 'novel_id' ] ][ 'chapterid' ] ) ? '读至 '.$chapters_k_v[ $records_k_v[ $v[ 'novel_id' ] ][ 'chapterid' ] ][ 'chapter_name' ] : '尚未阅读';
                }
            }else{
                foreach($novels as $k=>$v){
                    $c = $this->_novelchapterDao->getNovelChapterList( array( 'chapter_novel_id' => $v['novel_id'] ) );
                    $novels[ $k ][ 'chapter_id' ] = $c[0]['chapter_id'];
                    $novels[ $k ][ 'time' ] = '';
                    $novels[ $k ][ 'chapter_name' ] = '尚未阅读';
                }
            }
            
            $res['list'] = $novels;
            $res['count'] = count($novels);
        }
        return $res;
    }
    
    /**
     * 获取最近阅读
     */
    public function getUserReadRecord( $records = [] )
    {
        $res = [
            'list' => [],
            'count' => 0,
        ];
        $novelids = array_column( $records , 'novelid' );
        $chapterids = array_column( $records , 'chapterid' );
        $novels = $this->_novelDao->getNovelList( array ( 'novelids' => array ( 'novel_id' , $novelids ) ) );
        if( empty( $novels ) ){
            return false;
        }
        $novel_k_v = array_column ( $novels , null , 'novel_id' );
        unset( $novels );
        
        $chapters = $this->_novelchapterDao->getChapterList( array ( 'chapterids' => array ( 'chapter_id' , $chapterids ) ) );
        $chapter_k_v = array_column ( $chapters , null , 'chapter_id' );
        unset($chapters);
        
        $common_tools = new Tools_Common();
        foreach($records as $v){
            if( isset( $novel_k_v[ $v['novelid'] ] ) && isset( $chapter_k_v[ $v['chapterid'] ] ) && $v['novelid'] == $chapter_k_v[ $v['chapterid'] ][ 'chapter_novel_id' ] ){
                $res['list'][] = [
                    'novel_id'      => $novel_k_v[ $v['novelid'] ][ 'novel_id' ],
                    'novel_author'  => $novel_k_v[ $v['novelid'] ][ 'novel_author' ],
                    'novel_title'   => $novel_k_v[ $v['novelid'] ][ 'novel_title' ],
                    'novel_cover'   => $novel_k_v[ $v['novelid'] ][ 'novel_cover' ],
                    'chapter_id'    => $chapter_k_v[ $v['chapterid'] ][ 'chapter_id' ],
                    'chapter_name'  => '读至 '.$chapter_k_v[ $v['chapterid'] ][ 'chapter_name' ],
                    'time'          => $common_tools->time_format( $v[ 'time' ] ),
                ];
            }
        }
        $res['count'] = count($res['list']);
        
        return $res;
    }
    
    /**
     * 获取小说渠道分类列表
     */
    public function getChannelList( $params = [] , $records = [] )
    {
        $res = [
            'list'  => [],
            'count' => 0,
        ];
        
        if( !isset( $params['r_cate_id'] ) ){
            return $res;
        }
        
        $where = [];
        $where[ 'r_cate_id' ] = $params['r_cate_id'];
        $where[ 'page' ] = isset($params['page']) ? $params['page'] : 1;
        $where[ 'limit' ] = isset($params['limit']) ? $params['limit'] : 2;
        $novelIds = $this->_novelChannelRelation->getNovelIds( $where );
        
        $ids = [];
        if( $novelIds ){
            $ids = array_column ( $novelIds , 'r_novel_id' );
        }
        if($ids){
            $where   = array ();
            $where['novelids'] = array ( 'novel_id' , $ids );
        }
        $novels   = $this->_novelDao->getNovelList( $where );
        $result = [];
        if( $novels ){
            $n_k_v = array_column ( $novels , null , 'novel_id' );
            unset($novels);
            $chapters_k_v = [];
            $records_k_v = [];
            if( $records ){
                $records_k_v = array_column ( $records , null , 'novelid' );
                $chapters = $this->_novelchapterDao->getChapterList( array ( 'chapterids' => array ( 'chapter_id' , array_column ( $records , 'chapterid' ) ) ) );
                unset( $records );
                
                if( $chapters ){
                    $chapters_k_v = array_column ( $chapters , null , 'chapter_id' );
                }
            }
            
            $categorys = $this->_novelcategoryDao->getNovelCategoryList();
            $cate = array_column ( $categorys , 'cate_name' , 'cate_id' );
                
            $common_tools = new Tools_Common();
            $redis = RedisTool::getInstance();
            foreach($ids as $k=>$v){
                if( !isset( $n_k_v[$v] ) ){
                    continue;
                }
                $chapter = json_decode( $redis->get( 'XS_NOVEL_CHAPTER_KEY_' . $n_k_v[$v]['novel_id'] ) , true );
                $result[] = [
                    'novel_id'              => $n_k_v[$v]['novel_id'],
                    'novel_author'          => $n_k_v[$v]['novel_author'],
                    'novel_title'           => $n_k_v[$v]['novel_title'],
                    'novel_type'            => $n_k_v[$v]['novel_type'] == 1 ? '完结' : '连载',
                    'novel_category'        => $cate[$n_k_v[$v]['novel_category']],
                    'novel_cover'           => $n_k_v[$v]['novel_cover'],
                    'novel_introduction'    => $n_k_v[$v]['novel_introduction'],
                    'chapter_id'            => isset( $records_k_v[ $v ]) ? $records_k_v[ $v ][ 'chapterid' ] : $chapter[0]['chapter_id'],
                    'time'                  => isset( $records_k_v[ $v ]) ? $common_tools->time_format($records_k_v[ $v ][ 'time' ]) : '',
                    'chapter_name'          => isset( $records_k_v[ $v ][ 'chapterid' ] ) ? '读至 '.$chapters_k_v[ $records_k_v[ $v ][ 'chapterid' ] ][ 'chapter_name' ] : '尚未阅读',
                ];
            }
            
            $res['list'] = $result;
            $res['count'] = count($result);
        }
        return $res;
    }
    
    /**
     * 获取下一章id
     */
    public function getNextChapter( $params = [] )
    {
        if( !isset($params['chapter_novel_id']) || !isset($params['chapter_id']) ){
            return '加载失败';
        }
        $res = [
            'up' => 0,
            'down' => 0,
            'name' => '',
            'order' => 1,
        ];
        $list = $this->_novelchapterDao->getNovelChapterList( array ( 'chapter_novel_id' => $params['chapter_novel_id'] ) );
        $n = array_column ( $list , null , 'chapter_id' );
        $res['name'] = $n[$params['chapter_id']]['chapter_name'];
        $res['order'] = $n[$params['chapter_id']]['chapter_order'];
        unset($n);
        $l = array_column ( $list , 'chapter_order' , 'chapter_id' );
        $o = array_column ( $list , 'chapter_id' , 'chapter_order' );
        $order = $l[ $params['chapter_id'] ];
        if( isset($o[ $order + 1 ]) ){
            $res['down'] = $o[ $order + 1 ];
        }
        if( isset($o[ $order - 1 ]) ){
            $res['up'] = $o[ $order - 1 ];
        }
        return $res;
    }
    
    /**
     * 获取所有频道
     */
    public function getAllChannelList()
    {
        $novel = [];
        $channels = $this->_novelChannelCategory->getAllChannel();
        if( $channels ){
            $c = array_column ( $channels , null, 'cate_id' );
            foreach( $c as $k=>$v ){
                $novel[ $v['cate_name'] ] = $this->getChannelList( array ( 'r_cate_id' => $k ) );
                $novel[ $v['cate_name'] ]['id'] = $k;
            }
        }
        return $novel;
    }
    
    /**
     * 获取频道信息
     */
    public function getChannelInfo( $where = [] )
    {
        if( !$where['cate_id'] ){
            return false;
        }
        $info = $this->_novelChannelCategory->getChannelInfo( $where['cate_id'] );
        return $info ? $info : false;
    }
    
    /**
     * 获取新书
     */
    public function getNewBookList( $params = [] , $d = 0 )
    {
        $bookList = $this->_novelDao->getNewBookList( $params , $d );
        $categorys = $this->_novelcategoryDao->getNovelCategoryList();
        $cate = array_column ( $categorys , 'cate_name' , 'cate_id' );
        foreach($bookList['list'] as $k=>$n){
            $bookList['list'][$k]['novel_type'] = $n['novel_type'] == 1 ? '完结' : '连载';
            $bookList['list'][$k]['novel_category'] = $cate[$n['novel_category']];
        }
        return $bookList;
    }
    
    /**
     * 获取点击量排行
     */
    public function getClickBookList( $page = 1 , $pageSize = 10 , $d = 1 )
    {
        $bookList = $this->_novelDao->getClickBookList( $page , $pageSize , $d );
        $categorys = $this->_novelcategoryDao->getNovelCategoryList();
        $cate = array_column ( $categorys , 'cate_name' , 'cate_id' );
        foreach($bookList['list'] as $k=>$n){
            $bookList['list'][$k]['novel_type'] = $n['novel_type'] == 1 ? '完结' : '连载';
            $bookList['list'][$k]['novel_category'] = $cate[$n['novel_category']];
        }
        return $bookList;
    }
    
    /**
     * 获取连载完本排行
     */
    public function getTypeBookList( $page = 1 , $pageSize = 10 , $type = 1 , $d = 1 )
    {
        $bookList = $this->_novelDao->getTypeBookList( $page , $pageSize , $type , $d );
        $categorys = $this->_novelcategoryDao->getNovelCategoryList();
        $cate = array_column ( $categorys , 'cate_name' , 'cate_id' );
        foreach($bookList['list'] as $k=>$n){
            $bookList['list'][$k]['novel_type'] = $n['novel_type'] == 1 ? '完结' : '连载';
            $bookList['list'][$k]['novel_category'] = $cate[$n['novel_category']];
        }
        return $bookList;
    }
    
    /**
     * 获取热销书
     */
    public function getHotSaleList( $type = 1 , $page = 1 , $pageSize = 10 )
    {
        $res = [];
        $nids = [];
        $consumeModel = new Dao_UserConsumeModel();
        $list = $consumeModel->getTodayNovel( $type );
        $consume_count = count($list);
        $chargeModel = new Dao_NovelChargeModel();
        $ids_all = array_column( $list , 'novel_id' );
        if( $page == 1 ){   //如果是第一页  
            if( $consume_count >= $pageSize ){  //消费数大于等于每页条数，直接获取
                $nids = array_column( array_slice( $list , 0 , $pageSize ) , 'novel_id' );
            }else{  //消费数小于每页条数，获取最贵的和上架时间晚的
                $ids = array_column( $list , 'novel_id' );
                $highNovel = $chargeModel->getHighCostNovel( 0 , $pageSize - $consume_count , $ids );
                if(isset($highNovel['list']) && !empty($highNovel['list'])){
                    $h_nids = array_column( $highNovel['list'] , 'novel_id' );
                    $nids = array_merge_recursive( $ids , $h_nids );
                }
            }
        }else{  //不是第一页
            if( $consume_count >= $page * $pageSize ){  //消费数大于等于每页条数，直接获取
                $nids = array_column( array_slice( $list , ( $page - 1 ) * $pageSize , $pageSize ) , 'novel_id' );
            }else{  //消费数小于每页条数，获取最贵的和上架时间晚的
                $ids = array_column( array_slice( $list , ( $page - 1 ) * $pageSize , $consume_count ) , 'novel_id' );
                $offset = 0;
                $limit  = $page * $pageSize - $consume_count;
                if( count( $ids ) == '0' ){
                    $offset = $page - 2;
                    $limit  = $pageSize;
                }
                $highNovel = $chargeModel->getHighCostNovel( $offset , $limit , $ids_all );
                if(isset($highNovel['list']) && !empty($highNovel['list'])){
                    $h_nids = array_column( array_slice( $highNovel['list'] , ( $page - 1 ) * $pageSize - $consume_count ) , 'novel_id' );
                    $nids = array_merge_recursive( $ids , $h_nids );
                }
            }
        }
        $highNovelCount = $chargeModel->getHighCostNovelCount($ids_all);
        $where['novelids'] = array( 'novel_id' , $nids );
        $novels = $this->_novelDao->getNovelList( $where );
        $n_k_v = array_column( $novels , null , 'novel_id' );
        unset($novels);
        foreach( $nids as $v ){
            if( isset( $n_k_v[ $v ] ) ){
                $res[]  = $n_k_v[ $v ];
            }
        }
        $categorys = $this->_novelcategoryDao->getNovelCategoryList();
        $cate = array_column ( $categorys , 'cate_name' , 'cate_id' );
        foreach($res as $k=>$n){
            $res[$k]['novel_type'] = $n['novel_type'] == 1 ? '完结' : '连载';
            $res[$k]['novel_category'] = $cate[$n['novel_category']];
        }
        $data['list'] = $res;
        $data['total'] = $highNovelCount + $consume_count;
        return $data;
    }
    
    /**
     * 关键词搜索
     */
    public function getByKeyword( $kw = '' , $page = 1 , $orderBy = 0 , $pageSize = 10 )
    {
        if( $kw == '' ){
            return [];
        }
        $params = [
            'kw'        => $kw,
            'page'      => $page,
            'orderBy'   => $orderBy,
            'pageSize'  => $pageSize,
        ];
        $list = $this->_novelDao->getNewBookList( $params );
        return $list;
    }

    /**
     * 获取首页banner
     */
    public function getBannerList()
    {
        $list = $this->_novelBanner->getBannerList();
        return $list ? $list : false;
    }
    
    /**
     * 获取章节详情
     * @param type $chaprer_id
     * @return type
     */
    public function getChapterInfo($chaprer_id){
        $info = $this->_novelchapterDao->getChapterInfo( [
            'chapterid' => array( 'chapter_id' , $chaprer_id ) 
        ]);
        return $info;
    }
    
    /**
     * 花钱买章节
     */
    public function payChapter($uid,$novelid,$chapterid,$charge_price){
        $info = $this->_userDao->getUserInfo([ 'user_id' => $uid ]);
        $data['user_balance'] = $info['user_balance'] - ($charge_price/100);
        $data['user_balance_used'] = $info['user_balance_used'] + ($charge_price/100);
        $where[] = [ 'user_id',$uid];
        $res = $this->_userDao->editUser($data,$where);
        $res = 1;
        if($res){
            $novel_info = $this->_novelDao->getNovelInfo(['novel_id' => $novelid]);
            $consume_data = [
                'user_id' => $uid,
                'status' => 1,
                'pay_coin' => $charge_price,
                'novel_id' => $novelid,
                'novel_chapter' => $chapterid,
                'pay_time' => date('Y-m-d H:i:s'),
                'novel_title' => $novel_info['novel_title'],
                'phone' => $info['user_phone'],
                'main' => $novel_info['novel_main_category'],
                'category' => $novel_info['novel_category'],
            ];
            $ret = $this->_userConsume->addConsume($consume_data);
        }
        return $res;
    }
}
